import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import Asset from '@/views/asset/index.vue';
import AssetAccountAdd from '@/views/asset/add/AssetAccountAdd.vue';
import Bill from '@/views/bill/index.vue';
import Forms from '@/views/forms/index.vue';
import More from '@/views/more/index.vue';
import BillEdit from '@/views/bill/edit/BillEdit.vue';
import BIllTagAdd from '@/views/bill/edit/BIllTagAdd.vue';
import { UserModule } from '@/store/modules/user';
import { BillModule } from '@/store/modules/bill';

Vue.use(VueRouter);

const routes: RouteConfig[] = [
  {
    path: '/',
    redirect: './asset',
  },
  {
    path: '/asset',
    name: 'Asset',
    component: Asset,
  },
  {
    path: '/bill',
    name: 'Bill',
    component: Bill,
  },
  {
    path: '/forms',
    name: 'Forms',
    component: Forms,
  },
  {
    path: '/more',
    name: 'More',
    component: More,
  },
  {
    path: '/bill-edit',
    name: 'BillEdit',
    component: BillEdit,
  },
  {
    path: '/asset-account-add',
    name: 'AssetAccountAdd',
    component: AssetAccountAdd,
  },
  {
    path: '/bill-tag-add',
    name: 'BIllTagAdd',
    component: BIllTagAdd,
  },
];

const router = new VueRouter({
  mode: 'history',
  base: getAbsolutePath(),
  routes,
});

function getAbsolutePath() {
  const path = location.pathname;
  return path.substring(0, path.lastIndexOf('/') + 1);
}

router.afterEach((to) => {
  const path = to.path.slice(1);
  UserModule.toggleCurrentActive(path);
});
export default router;
